#ifndef _TITLE_MANANGER_H_
#define _TITLE_MANANGER_H_

#include "Common.h"
#include "Resource.h"
#include "ResourceManager.h"
#include "Singleton.h"
#include "String.h"
#include "Titles.h"
#include "NGLog.h"

class  TitleManager: public ResourceManager,public Singleton<TitleManager>
{
public:
	TitleManager();
	~TitleManager();

	String	getTitleStringName(const uint32 & serial);
	
	ResourcePtr  create(const uint32 & serial,const NameValuePairList* params = 0);
	ResourceCreateOrRetrieveResult  \
		createOrRetrieve(const uint32 & serial,const NameValuePairList* params = 0);
	ResourcePtr  load(const uint32 & serial);

	//user manager start
	void	Startup(const uint32 & gid,bool isBattle = true);
	void 	Shutdown(void);

	//脫脙脫脷碌脙碌陆脪禄赂枚Title陆谩鹿鹿拢卢脫脙脫脷脧貌脢媒戮脻驴芒脳路录脫脨脗脨搂鹿没碌脛录脟脗录
	Resource * newDumyTitle(void);
	void	freeDumyTitle(Resource * dumy);

	//赂霉戮脻脛拢掳氓脧貌脢媒戮脻驴芒虏氓脠毛脨脗碌脛录脟脗录拢卢路碌禄脴虏氓脠毛碌脛录脟脗录
	ResourcePtr	createTitleDatabase(Resource * dumy);
	ResourcePtr	loadTitleDatabase(Resource * dumy);

	//赂霉戮脻虏茅脩炉拢卢路碌禄脴路没潞脧脤玫录镁碌脛录脟脗录 offset 脦陋路颅脪鲁脝冒碌茫 limitcount 脦陋脠隆禄脴脳卯麓贸脢媒脕驴 query 脦陋虏茅脩炉脤玫录镁脭脷 WHERE脰庐潞贸
	bool	getTitleList(std::list<TitlePtr> * titles,const uint32 & offset,const uint32 & limitcount,const char * query,...);

	//赂霉戮脻虏茅脩炉脤玫录镁路碌禄脴脪禄赂枚虏茅脩炉陆谩鹿没脢媒脕驴 query 脦陋脭脷WHERE脰庐潞贸碌脛SQL脫茂戮盲
	uint32	getDBCount(const char * query,...);
	
	ResourcePtr   newDBObject(void);
	ResourcePtr   getDBObjectByHandle(const uint32 & handle);
	bool	getDBObjects(std::list<ResourcePtr> * objs,const uint32 & offset,const uint32 & limitcount,const char * query,...);
	
protected:
	uint32		m_default_gid;
	String		m_default_group;
       /// @copydoc ResourceManager::createImpl
        Resource* createImpl(const String& name, ResourceHandle handle,
            const String& group, bool isManual, ManualResourceLoader* loader,
            const NameValuePairList* createParams);
};


#define   sTitleMgr   TitleManager::getSingleton()



#endif
